package Tree;

import java.util.*;

class TreeNode {
    public char val;
    public TreeNode left;
    public TreeNode right;
    
    TreeNode(char val) {
        this.val = val;
    }
}

public class Main {
    public static int i;
    public static TreeNode createTree(String str) {
        TreeNode cur = null;
        if(str.charAt(i) != '#') {
            cur = new TreeNode(str.charAt(i));
            i++;
            cur.left = createTree(str);
            cur.right = createTree(str);
        } else {
            i++;
        }
        return cur;
    }
    
    public static void inoder(TreeNode root) {
        if(root == null) return;
        
        inoder(root.left);
        System.out.print(root.val + " ");
        inoder(root.right);
    }
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        ArrayList
        while(scan.hasNextLine()) {
            String str = scan.nextLine();
            TreeNode root = createTree(str);
            inoder(root);
        }
    }
}